package SV_EMAIL;
import javax.mail.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.mail.internet.*;
import java.io.IOException;
import java.util.Properties;



public class Vulnerable_02 {
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        try {
            // Get system properties
            Properties props = System.getProperties();
            // Setup mail server
            props.put("mail.smtp.host", "my.company.com");
            // Get session
            Session session = Session.getDefaultInstance(props, null);
            // Define message
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress("admin@my.company.com"));
            final String email = req.getParameter("email");
            Address addr = new InternetAddress(email);
            message.setRecipient(Message.RecipientType.TO, addr);
            String subject = "";
            message.setSubject(subject);
            String text = "";
            message.setText(text);
            // Send message
            Transport.send(message);
        } catch (AddressException e) {
            throw new ServletException(e);
        } catch (MessagingException e) {
            throw new ServletException(e);
        }
    }
}
